package com.fyzk.activity.trend;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.RadioButton;

import com.alibaba.fastjson.JSON;
import com.fyzk.activity.lottery.shuzicai.klpk.KLPKPopupItemBean;
import com.fyzk.activity.lottery.shuzicai.klpk.KLPKPopupwindow;
import com.tyjc.lottery.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by fanxs11 on 2017/7/20.
 */

public class Gp11x5TrendActivity extends TrendBaseActivity implements CompoundButton
        .OnCheckedChangeListener {

    private int[] popup_itemsId = {R.string.gp_11xuan5_popu_ren2,
            R.string.gp_11xuan5_popu_ren3, R.string.gp_11xuan5_popu_ren4,
            R.string.gp_11xuan5_popu_ren5, R.string.gp_11xuan5_popu_ren6,
            R.string.gp_11xuan5_popu_ren7, R.string.gp_11xuan5_popu_ren8,
            R.string.gp_11xuan5_popu_qian1, R.string.gp_11xuan5_popu_qian2_zhi,
            R.string.gp_11xuan5_popu_qian2_zu,
            R.string.gp_11xuan5_popu_qian3_zhi,
            R.string.gp_11xuan5_popu_qian3_zu,
            R.string.gp_11xuan5_popu_ren2_dan,
            R.string.gp_11xuan5_popu_ren3_dan,
            R.string.gp_11xuan5_popu_ren4_dan,
            R.string.gp_11xuan5_popu_ren5_dan,
            R.string.gp_11xuan5_popu_ren6_dan,
            R.string.gp_11xuan5_popu_ren7_dan,
            R.string.gp_11xuan5_popu_qian2_zu_dan,
            R.string.gp_11xuan5_popu_qian3_zu_dan};
    private List<KLPKPopupItemBean> popup_items = new ArrayList<>();
    private KLPKPopupwindow top_popup;

    private RadioButton rb1;
    private RadioButton rb2;
    private RadioButton rb3;
    private RadioButton rb4;

    private Gp11x5TrendView gp11x5TrendView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        //顶部
        for (int i = 0; i < popup_itemsId.length; i++) {

            KLPKPopupItemBean itemBean = new KLPKPopupItemBean();
            itemBean.str1 = getString(popup_itemsId[i]);
            popup_items.add(itemBean);
        }

        top_popup = new KLPKPopupwindow(this, AbsListView.LayoutParams.MATCH_PARENT, AbsListView
                .LayoutParams.WRAP_CONTENT,
                popup_items, 12);
        top_popup.setHm_PopupOnItemListener(this);

        onItem(popupId);
        top_popup.setCheckItem(popupId);
//        topView.setCenterText(""
//                + popup_items.get(popupId).str1);
    }

    @Override
    protected int getTopDownVisible() {
        return View.VISIBLE;
    }

    @Override
    protected View getChooseView() {
        View view = LayoutInflater.from(getContext()).inflate(R.layout.view_gp11x5_trend_choose,
                null);
        view.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        rb1 = (RadioButton) view.findViewById(R.id.trend_choose_rb1);
        rb2 = (RadioButton) view.findViewById(R.id.trend_choose_rb2);
        rb3 = (RadioButton) view.findViewById(R.id.trend_choose_rb3);
        rb4 = (RadioButton) view.findViewById(R.id.trend_choose_rb4);

        rb1.setOnCheckedChangeListener(this);
        rb2.setOnCheckedChangeListener(this);
        rb3.setOnCheckedChangeListener(this);
        rb4.setOnCheckedChangeListener(this);

        rb2.setChecked(true);
        return view;
    }


    @Override
    protected TrendBaseView getTrendView() {
        if(trendView == null){
            trendView = new Gp11x5TrendViewNew(getContext());
        }
        return trendView;
    }

    @Override
    protected TrendBean getTrendBean(String json) {
        return JSON.parseObject(json, Gp11x5TrendBean.class);
    }

    @Override
    protected String getBetCode(List<TrendBaseView.Drawinfor> infors) {
        return null;
    }

    @Override
    protected long getZhuShu(List<TrendBaseView.Drawinfor> infors) {
        return 0;
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if (isChecked) {
            if (trendView.listener != null) {
                trendView.listener.onChooseClick(buttonView.getId());
            }
        }
    }

    @Override
    public void onCenterClick() {
        top_popup.showPopupWindow(topView);
    }

    @Override
    public void onItem(int position) {
        super.onItem(position);
        topView.setCenterText("" + popup_items.get(position).str1);
        rb2.setChecked(true);
        if (trendView.listener != null) {
            trendView.listener.onChangePayType(position);
        }
        rb4.setVisibility(View.VISIBLE);
        switch (position) {
            case 7:
                rb2.setText("走势");
                rb3.setText("冷热");
                rb4.setVisibility(View.GONE);
                break;
            case 8:
                rb4.setVisibility(View.GONE);
                rb2.setText("万位走势");
                rb3.setText("千位走势");
                break;
            case 10:
                rb2.setText("万位走势");
                rb3.setText("千位走势");
                rb4.setText("百位走势");
                break;
            default:
                rb2.setText("走势");
                rb3.setText("冷热");
                rb4.setText("形态");
                break;
        }
    }
}
